<?php
/*
 * @Author: your name
 * @Date: 2020-11-06 14:45:02
 * @LastEditTime: 2020-12-17 13:37:50
 * @LastEditors: Please set LastEditors
 * @Description: 内网ip验证器
 * @FilePath: /special/application/adminapiv3/validate/IntranetIpValidate.php
 */
namespace app\adminapiv3\validate;

use think\Validate;

class IntranetIpValidate extends Validate
{
    protected $rule = [
        //资产位置ID
        'address_id|资产位置ID' => 'require|number|length:1,10',
        // 内/外网IP地址
        'ip|内/外网IP地址' => 'require|regex:^\d{1,3}(.\d{1,3}){3}([-,]\d{1,3}(.\d{1,3}){3}){0,20}$',
        //内/外网IP数据库ID
        'id|内/外网IP数据库ID' => 'require|number|length:1,10',
        //内/外网类型
        'type|内/外网类型' => 'require|in:extranet,intranet',
        // 内/外网IP数据库ID集合
        'id_s|内/外网IP数据库ID集合' => 'require|regex:^(\d+){1,30}$'
    ];

    protected $scene = [
        //添加
        'add' => ['address_id', 'ip'],
        //修改
        'modify' => ['id','address_id', 'ip'],
        //删除
        'delete' => ['id_s']
    ];

    protected $message = [
        'type.in' => '内/外网类型格式错误'
    ];

    /**
     * @name: 列表过滤
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-11-06 16:17:47
     */
    public function sceneListFilter ()
    {
        return $this->only(['type','ip','address_id'])
        ->remove('type', 'require')
        ->remove('ip', ['require'])
        ->append('ip', 'regex:^\d{1,3}(\.\d{1,3}){3}$');
    }
}